package com.quan.amqp.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.quan.common.base.constant.CommonConstant;
import com.quan.common.utils.RandomUitl;
import com.quan.system.entity.SystemUser;

/**
 * 消息生产端-邮件发送
 * 
 * @author yhaoquan
 *
 */
@Component
public class MailMessageProducer {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private RabbitTemplate rabbitTemplate;

	/**
	 * 发送日志消息
	 * 
	 * @param entity
	 */
	public void sender(SystemUser entity) {
		logger.info("-----------------------消息生产端----------------------------");
		// 发送消息(交换机 exchange, 路由键 routingKey, 消息体内容, 消息唯一ID)
		this.rabbitTemplate.convertAndSend(CommonConstant.EXCHANGE_TOPIC_MAIL, CommonConstant.QUEUE_TOPIC_MAIL, entity, new CorrelationData(RandomUitl.uuid()));
		logger.info("发送邮件消息==>>{}", JSON.toJSONString(entity));
	}

}
